﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using MediSIIM.Message;
using System.Xml.Serialization;
using System.Text;
using System.Xml;

namespace SIIMWeb.YIBAO
{
    public class TradeType
    {
        /// <summary>
        /// 诊疗代码对照:[操作员代码、操作员姓名、操作日期、医院编码、产地代码、医院名称、医保编码]
        /// </summary>
        public static KeyValue ZLDMDZ = new KeyValue("ZHENLIAOMLDZ", InXml.ZLDMDZ);
        /// <summary>
        /// 药品代码对照:[操作员代码、操作员姓名、操作日期、医院编码、产地代码、医院名称、医保编码]
        /// </summary>
        public static KeyValue YPDMDZ = new KeyValue("YAOPINMLDZ", InXml.ZLDMDZ);
        /// <summary>
        /// 疾病代码对照:[操作员代码、操作员姓名、操作日期、项目序号、项目名称、医保代码]
        /// </summary>
        public static KeyValue JBDMDZ = new KeyValue("JIBINGMLDZ", InXml.JBDMDZ);
        /// <summary>
        /// 诊疗代码对照:[操作员代码、操作员姓名、操作日期、项目序号]
        /// </summary>
        public static KeyValue ZLDMSC = new KeyValue("ZHENLIAOMLDZ", InXml.MLDMSC);
        /// <summary>
        /// 药品代码对照:[操作员代码、操作员姓名、操作日期、项目序号]
        /// </summary>
        public static KeyValue YPDMSC = new KeyValue("YAOPINMLDZ", InXml.MLDMSC);
        /// <summary>
        /// 疾病代码对照:[操作员代码、操作员姓名、操作日期、项目序号]
        /// </summary>
        public static KeyValue JBDMSC = new KeyValue("JIBINGMLDZ", InXml.JBDMSC);
    }

    public class DataUtil
    {
        public static T GetObject<T>(string xml)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                byte[] bytes = MQMessage.Default_Encoding.GetBytes(xml);
                ms.Write(bytes, 0, bytes.Length);
                ms.Flush();
                ms.Position = 0;
                XmlSerializer xs = new XmlSerializer(typeof(T));
                return (T)xs.Deserialize(ms);
            }
        }

        public static string GetXml(object inobj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var xmlSerializerNamespaces = new XmlSerializerNamespaces();
                xmlSerializerNamespaces.Add("", "");
                new XmlSerializer(inobj.GetType()).Serialize(new XmlTextWriter(ms, Encoding.UTF8), inobj, xmlSerializerNamespaces);
                ms.Flush();
                ms.Position = 0;
                using (StreamReader sr = new StreamReader(ms))
                {
                    string str = sr.ReadToEnd();
                    return str;
                }
            }
        }
    }
}